<template>
  <div class="Sort-box">
    <!-- 商品分类左侧 -->
    <van-nav-bar title="商品分类" left-text="返回" left-arrow @click-left="GoBack">
      <template #right>
        <van-icon name="search" size="18" />
      </template>
    </van-nav-bar>
    <!-- 商品内容右侧 -->
    <van-tree-select
      class="Sort-content"
      height="55vw"
      :items="items"
      :main-active-index.sync="active"
      @click-nav="getName"
    >
      <template #content>
        <van-grid>
          <van-grid-item
            icon="photo-o"
            :text="item.brand"
            v-for="(item, index) in SortList"
            :key="index"
            class="Sort-name"
            @click="goBrand(item.brand)"
          />
        </van-grid>
      </template>
    </van-tree-select>
    <FooterBarVue></FooterBarVue>
  </div>
</template>

<script>
import FooterBarVue from "@/components/FooterBar.vue";
export default {
  name: "Sort",
  components: {
    FooterBarVue,
  },
  data() {
    return {
      active: 0,
      items: [],
      SortList: [],
      category: "手机"
    };
  },
  created() {
    this.service({
      url: "/pro/categorylist",
    }).then((res) => {
      if (res.data.code == 200) {
        this.items = res.data.data.map((item) => {
          return { text: item };
        });
      }
    });
    this.service({
      url: "/pro/categorybrandlist",
      params: {
        category: this.category,
      },
    }).then((res) => {
      this.SortList = res.data.data;
    });
  },
  methods: {
    /* 拿到某种类 */
    getName(index) {
      this.service({
        url: "/pro/categorybrandlist",
        params: {
          category: this.items[index].text,
        },
      }).then((res) => {
        this.SortList = res.data.data;
        this.category = this.items[index].text
      });
    },
    /* 点击返回 */
    GoBack(){
      this.$router.go(-1);
    },
    /* 去某品牌 */
    goBrand(brand){
      this.$router.push({path: "/SearchResult", query: {category:this.category, brand}});
      
    }
  },
};
</script>

<style scoped>
.Sort-box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.Sort-content {
  flex: 1;
  overflow: auto;
}
.Sort-name{
  /* display: block; */
  width: 20%;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>